
package com.enjoyiot.module.bms.dal.mysql.asset;

import com.enjoyiot.framework.common.pojo.PageResult;
import com.enjoyiot.framework.mybatis.core.mapper.BaseMapperX;
import com.enjoyiot.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.enjoyiot.module.bms.controller.admin.asset.vo.AssetPageReqVO;
import com.enjoyiot.module.bms.dal.dataobject.AssetDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;
import java.util.stream.Collectors;

@Mapper
public interface AssetMapper extends BaseMapperX<AssetDO> {

    default PageResult<AssetDO> selectPage(AssetPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<AssetDO>()
                .likeIfPresent(AssetDO::getAssetName, reqVO.getAssetName())
                .likeIfPresent(AssetDO::getLocation, reqVO.getLocation())
                .eqIfPresent(AssetDO::getType, reqVO.getType())
                .eqIfPresent(AssetDO::getStatus, reqVO.getStatus())
                .likeIfPresent(AssetDO::getAssetSn, reqVO.getAssetSn())
                .betweenIfPresent(AssetDO::getPurchaseTime, reqVO.getPurchaseTime())
                .orderByDesc(AssetDO::getId));
    }

    default List<AssetDO> selectSimpleList(String assetName) {
        return selectList(new LambdaQueryWrapperX<AssetDO>()
                .likeIfPresent(AssetDO::getAssetName, assetName)
                .eq(AssetDO::getStatus, 1)
                .eq(AssetDO::getType, 0)
                .notIn(AssetDO::getCategoryId, 1, 7, 91));
    }

    default List<Long> selectNotExistAssetIds(List<Long> ids){
        //查询bms_device的asset_id中type=1但是not in ids的所有id
        return selectList(new LambdaQueryWrapperX<AssetDO>()
                .eq(AssetDO::getType, 1)
                .eq(AssetDO::getStatus, 1)
                .notIn(AssetDO::getId, ids))
                .stream()
                .map(AssetDO::getId)
                .collect(Collectors.toList());
    }
}
